<?php

define('IN_SEXMALL', true);

require('./config/db.config.php');
require('./includes/cls_mysql.php');

// 创建DB对象
$db = new cls_mysql(DBHOST, DBUSER, DBPWD, DBNAME);
$request_url = trim(strip_tags($_SERVER['REQUEST_URI']),'/');
$len = strlen($request_url);
if($len ==4)
{
	$shortcode = $request_url;
	//$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
	$sql = "SELECT article_id,link FROM ".TABLEPRE."article WHERE is_open=1 and shortcode='".$shortcode."' LIMIT 1";
	$row = $db->getRow($sql);
	if ($row['link'] && ltrim($row['link'],'http://') ) {
		// 如果设置了跳转链接，则直接跳转链接
		header("Location: ".$row['link']);
		exit;

	}else if ($row['article_id']){
		// 文章阅读
		header("Location: index.php?m=article&id=".$row['article_id']."&f=".$shortcode);
		exit;
	}
}
header("Location: /");
//header("HTTP/1.1 404 Not Found");
?>